//
//  ProfileCell.m
//  SinaWeibo
//
//  Created by Apple on 16/8/22.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "ProfileCell.h"
#import "ItemModel.h"
#import "GroupModel.h"
#import "ItemSwitchModel.h"
#import "ItemArrowModel.h"

@implementation ProfileCell



-(void)setItem:(ItemModel *)item{
    
    _item = item;
    //如果icon是空就会报下面的警告
    //CUICatalog: Invalid asset name supplied: (null)
    
    if (item.icon) {
        self.imageView.image = [UIImage imageNamed:item.icon];
    }
    
    self.textLabel.text = item.title;
    if (item.subTitle) {
        //设置子标题
        self.detailTextLabel.text = item.subTitle;
    }
    //设置标题文字的大小
    self.textLabel.font = [UIFont systemFontOfSize:16];
    //设置子标题的字体颜色
    self.detailTextLabel.font = [UIFont systemFontOfSize:12];
    self.detailTextLabel.textColor = [UIColor grayColor];
    
    
    //判断显示箭头还是开关
    if ([item isKindOfClass:[ItemArrowModel class]]) {
        //设置箭头
        self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_arrow"]];
        
    }else if([item isKindOfClass:[ItemSwitchModel class]]){
        //设置开关
        self.accessoryView = [[UISwitch alloc] init];
        //cell不可以被选中
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }else{
        
        self.accessoryView = nil;
    }

    
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    CGFloat margin = 5;
    
    CGFloat detalLabelX = CGRectGetMaxX(self.textLabel.frame) + margin;
    CGFloat detalLabelY = self.detailTextLabel.frame.origin.y;
    CGFloat detalLabelWidth = self.detailTextLabel.frame.size.width;
    CGFloat detalLabelHeight = self.detailTextLabel.frame.size.height;
    
    self.detailTextLabel.frame = CGRectMake(detalLabelX, detalLabelY, detalLabelWidth, detalLabelHeight);
    
}

@end
